<template>
    <div class="contener">
        <div class="tree-page">
            <!-- 左侧树 -->
            <div class="tree-menu">
                <base-tree
                    :data="baseTreeConfig.data"
                    :loading="baseTreeConfig.loading"
                    :currentNodeKey="baseTreeConfig.currentNodeKey"
                    :filterShow="baseTreeConfig.filterShow"
                    :defaultExpandAll="baseTreeConfig.defaultExpandAll"
                    @NodeClick="handelTreeClick"
                />
            </div>
            <!-- 页面 -->
            <div class="page">
                <!-- 搜索 -->
                <transition
                    @before-enter="_beforeEnter"
                    @enter="_enter"
                    @after-enter="_afterEnter"
                    @before-leave="_beforeLeave"
                    @leave="_leave"
                    @after-leave="_afterLeave"
                >
                    <div
                        class="search-contener"
                        ref="searchContener"
                        v-show="searchFormConfig.searchContenerShow"
                    >
                        <base-form
                            :formItems="searchFormConfig.formItems"
                            :formData="searchFormConfig.formSubmit"
                            ref="searchForm"
                            @onButtonClick="searchBarButtonClick"
                        />
                    </div>
                </transition>
                <!-- 表格 -->
                <div class="datas-contener">
                    <!-- 表格操作项 -->
                    <div class="option-contener">
                        <data-options
                            @buttonClick="handelOptionClick"
                            :leftConfig="dataOptionConfig.leftConfig"
                        />
                    </div>
                    <!-- 表格展示项 -->
                    <div class="table-contener">
                        <base-table
                            ref="baseTable"
                            :tableData="baseTableConfig.tableData"
                            :tableHeader="baseTableConfig.tableHeader"
                            :tableConfig="baseTableConfig.tableConfig"
                            @handleSelection="tableDataSelected"
                        >
                            <template slot-scope="{ scope }">
                                <span v-if="scope.type === 'index'">
                                    {{ scope.$index + 1 }}
                                </span>
                                <div v-if="scope.type === 'handle'">
                                    <el-button
                                        type="text"
                                        @click.stop="updateTableData(scope.row)"
                                        v-hasPermi="[
                                            '/tool/dmd/dataCurd/update'
                                        ]"
                                        >修改</el-button
                                    >
                                    <el-button
                                        type="text"
                                        @click.stop="deleteTableData(scope.row)"
                                        v-hasPermi="[
                                            '/tool/dmd/dataCurd/delete'
                                        ]"
                                        >删除</el-button
                                    >
                                </div>
                                <div v-if="scope.type === 'handle1'">
                                    <el-button
                                        type="text"
                                        @click.stop="
                                            showSubTableData(scope.row)
                                        "
                                        v-hasPermi="['*']"
                                        >明细数据</el-button
                                    >
                                    <el-button
                                        type="text"
                                        @click.stop="updateTableData(scope.row)"
                                        v-hasPermi="[
                                            '/tool/dmd/dataCurd/update'
                                        ]"
                                        >修改</el-button
                                    >
                                    <el-button
                                        type="text"
                                        @click.stop="deleteTableData(scope.row)"
                                        v-hasPermi="[
                                            '/tool/dmd/dataCurd/delete'
                                        ]"
                                        >删除</el-button
                                    >
                                </div>
                            </template>
                        </base-table>
                    </div>
                    <!-- 分页 -->
                    <div class="paging-contener">
                        <pagin-ation
                            :size="paginationConfig.size"
                            :total="paginationConfig.total"
                            :type="paginationConfig.type"
                            :currentPage="paginationConfig.currentPage"
                            @PageNumber="pageNumberChange"
                            @PageSize="pageSizeChange"
                        />
                    </div>
                </div>
            </div>
        </div>
        <!-- 弹框 -->
        <el-dialog
            :title="dialogConfig.title"
            :visible.sync="dialogConfig.show"
            :width="dialogConfig.width"
            v-dialogDrag
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            append-to-body
        >
            <!-- 筛选表格列 -->
            <div
                class="dialog-content"
                v-if="dialogConfig.key === 'tableColumn'"
            >
                <base-transfer
                    :transferConfig="tableColumnTransferConfig"
                    ref="baseTransfer"
                />
            </div>
            <!-- 新增 -->
            <div
                class="dialog-content"
                v-if="dialogConfig.key === 'addTableData'"
            >
                <base-form
                    :formItems="addFormConfig.formItems"
                    :formData="addFormConfig.formSubmit"
                    :formConfig="addFormConfig.formConfig"
                    :formRules="addFormConfig.formRule"
                    ref="addForm"
                    @onButtonClick="addFormButtonClick"
                />
            </div>
            <!-- 修改 -->
            <div
                class="dialog-content"
                v-if="dialogConfig.key === 'updateTableData'"
            >
                <base-form
                    :formItems="updateFormConfig.formItems"
                    :formData="updateFormConfig.formSubmit"
                    :formConfig="updateFormConfig.formConfig"
                    :formRules="updateFormConfig.formRule"
                    ref="updateForm"
                    @onButtonClick="updateFormButtonClick"
                />
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="handelCloseDialog"
                    >取 消</el-button
                >
                <el-button
                    size="small"
                    type="primary"
                    @click="handelCofimeDialog"
                    >确 定</el-button
                >
            </span>
        </el-dialog>
    </div>
</template>
<script>
import BaseTree from '@/components/baseTree/index'
import BaseForm from '@/components/baseForm/index'
import DataOptions from '@/components/dataOptions/index'
import BaseTable from '@/components/baseTable/index'
import PaginAtion from '@/components/pagination/index'
import BaseTransfer from '@/components/baseTransfer/index'
import globalMixin from '@/mixins/global'
import {
    getBusModelTree,
    busModelDataList,
    getBusModelColsData,
    busModelDataSave,
    busModelDataUpdate,
    busModelDataDelete
} from '@/http/apis/tool/dmd/dataInfo'
import { getDictDatas } from '@/plugins/dict'
import { assemblyDataByTableColumn } from '@/utils/tool'
export default {
    components: {
        BaseTree,
        BaseForm,
        DataOptions,
        BaseTable,
        PaginAtion,
        BaseTransfer
    },
    mixins: [globalMixin],
    data() {
        return {
            //表格数据的主键字段
            curRowDataKey: '',
            curTableInfo: {},
            //当前模型表字段列表
            curColumnList: [],
            //搜索按钮数据
            searchButtonList: [
                {
                    ltype: 'button',
                    type: 'primary',
                    text: '搜索',
                    prop: 'searchDatas',
                    icon: 'el-icon-search',
                    width: 'w-auto',
                    loading: false
                },
                {
                    ltype: 'button',
                    type: 'default',
                    text: '重置',
                    prop: 'resetSearchForm',
                    icon: 'el-icon-refresh-right',
                    width: 'w-auto'
                }
            ],
            // 通用树组件配置
            baseTreeConfig: {
                // tree的数据
                data: [],
                // tree的加载状态
                loading: false,
                // tree选中的树
                currentNodeKey: '',
                // 过滤显示
                filterShow: true,
                //默认展开
                defaultExpandAll: true
            },
            // 搜索表单配置
            searchFormConfig: {
                formItems: [],
                formSubmit: {},
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: 'auto'
                },
                // 搜索控件是否显示
                searchContenerShow: true
            },
            // 数据操作项配置
            dataOptionConfig: {
                // 左侧按钮配置
                leftConfig: [
                    {
                        prop: 'addTableData',
                        label: '新增',
                        icon: 'el-icon-plus',
                        type: 'primary',
                        disabled: false,
                        hasPermi: ['/tool/dmd/dataCurd/save']
                    }
                ]
            },
            // 表格配置
            baseTableConfig: {
                // 表格数据
                tableData: [],
                // 表格头数据
                tableHeader: [
                    {
                        type: 'selection',
                        width: 50,
                        fixed: 'left',
                        label: '选择',
                        visible: true
                    },
                    {
                        type: 'index',
                        label: '序号',
                        width: 50,
                        visible: true
                    }
                ],
                // 表格配置
                tableConfig: {
                    loading: false
                },
                // 选中的表格数据
                tableCheckedDatas: []
            },
            // 分页配置
            paginationConfig: {
                type: 'md',
                size: 10,
                currentPage: 1,
                total: 100
            },
            // 弹框配置
            dialogConfig: {
                // 弹框标题
                title: '新增',
                // 是否显示
                show: false,
                // 宽度
                width: 'auto',
                // 弹框标识(用来区分弹框内容)
                key: ''
            },
            // 查询表格数据的参数
            queryTableParams: {
                pageNo: 0,
                pageSize: 10,
                entity: {}
            },
            // 表格列筛选配置
            tableColumnTransferConfig: {
                // 穿梭框的数据
                data: [],
                // 穿梭框的标题
                titles: ['显示', '隐藏'],
                // 隐藏的列
                modelList: []
            },
            // 新增表单配置
            addFormConfig: {
                // 表单项
                formItems: [],
                // 提交项
                formSubmit: {},
                // 配置项
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: '80px'
                },
                // 验证项
                formRule: {}
            },
            // 修改表单配置
            updateFormConfig: {
                // 表单项
                formItems: [],
                // 提交项
                formSubmit: {},
                // 配置项
                formConfig: {
                    labelPosition: 'right', // label对齐方式
                    labelWidth: '80px'
                },
                // 验证项
                formRule: {}
            }
        }
    },
    created() {
        this.initPage()
    },
    methods: {
        /**
         * 页面开始
         */
        async initPage() {
            // 查询部门树列表
            await this.queryBusModelTree()
            //查询模型列数据
            if (this.curTableInfo) {
                await this.queryBusModelColsData(
                    this.curTableInfo.tableId,
                    this.curTableInfo.tableName
                )
                // 查询用列表
                this.queryTableParams.entity.tableId = this.curTableInfo.tableId
                this.queryTableParams.entity.tableName = this.curTableInfo.tableName
                this.queryTableData(this.queryTableParams)
            }
        },
        /**
         * 左侧部门树相关
         */
        /**
         * 查询模型树
         */
        async queryBusModelTree() {
            try {
                let res = await getBusModelTree()
                if (res && res.data) {
                    this.baseTreeConfig.data = res.data.treeVos
                    this.curTableInfo = res.data.default
                    this.baseTreeConfig.currentNodeKey = res.data.default.id
                } else {
                    this.baseTreeConfig.data = []
                    this.curTableInfo = {}
                }
            } catch (error) {
                this.baseTreeConfig.loading = false
            }
        },
        /**
         * 查询模型列数据
         */
        async queryBusModelColsData(tableId, tableName) {
            try {
                let params = {
                    tableId: tableId,
                    tableName: tableName
                }
                let res = await getBusModelColsData(params)
                await this.getRowDataKeys(res.data.cols)
                await this.bulidSearchFormConfig(res.data.cols)
                await this.bulidTableHeader(res.data.cols)
                await this.bulidOperCols(res.data.table)
                await this.bulidAddFormConfig(res.data.cols)
                await this.bulidUpdateFormConfig(res.data.cols)
                await this.bulidFormRule(res.data.cols)
                // 设置表单的配置项
                await this.setFormsItems()
            } catch (error) {
                this.curColumnList = []
            }
        },
        /**
         * 获取模型的主键字段
         */
        getRowDataKeys(data) {
            //过滤主键数据
            let keyData = data.filter(v => {
                return v.pk
            })
            this.curRowDataKey = keyData[0].javaField
        },
        /**
         * 构建搜索框配置
         * @param {Array} data
         */
        bulidSearchFormConfig(data) {
            //过滤搜索条件数据
            let searchData = data.filter(v => {
                return v.query
            })

            this.searchFormConfig.formItems = []
            let formItems = []
            for (var i = 0; i < searchData.length; i++) {
                let v = searchData[i]
                if (formItems.length > 4) {
                    this.searchFormConfig.formItems.push(formItems)
                    formItems = []
                }
                formItems.push({
                    ltype: v.htmlType,
                    placeholder: '请输入' + v.columnComment,
                    label:
                        v.columnComment.length > 4
                            ? v.columnComment.substr(0, 4)
                            : v.columnComment,
                    prop: v.javaField,
                    width: 'w-2'
                })
                if (this.searchFormConfig.formSubmit[v.javaField]) {
                    this.$set(
                        this.searchFormConfig.formSubmit,
                        this.searchFormConfig.formSubmit[v.javaField],
                        ''
                    )
                }
            }
            let newFormItems = formItems.concat(this.searchButtonList)
            this.searchFormConfig.formItems.push(newFormItems)
        },
        /**
         * 构建表头
         * @param {Array} data
         */
        bulidTableHeader(data) {
            //过滤列表条件数据
            let listData = data.filter(v => {
                return v.list
            })
            this.baseTableConfig.tableHeader = []
            listData.forEach(v => {
                if (v.columnComment) {
                    this.baseTableConfig.tableHeader.push({
                        prop: v.javaField,
                        label: v.columnComment,
                        visible: true,
                        showOverflowTooltip: true
                    })
                }
            })
        },
        /**
         * 构建列操作
         * @param {Array} data
         */
        bulidOperCols(data) {
            if (data.subTableName) {
                this.baseTableConfig.tableHeader.push({
                    label: '操作',
                    type: 'handle1',
                    width: 160,
                    visible: true
                })
            } else {
                this.baseTableConfig.tableHeader.push({
                    label: '操作',
                    type: 'handle',
                    width: 120,
                    visible: true
                })
            }
        },
        /**
         * 构建新增弹框配置
         * @param {Array} data
         */
        bulidAddFormConfig(data) {
            //过滤新增表单数据
            let insertData = data.filter(v => {
                return v.insert
            })
            this.addFormConfig.formItems = []
            let formItem = []
            for (var i = 0; i < insertData.length; i++) {
                let v = insertData[i]
                if (formItem.length > 2) {
                    this.addFormConfig.formItems.push(formItem)
                    formItem = []
                }
                if (v.htmlType === 'input') {
                    formItem.push({
                        ltype: 'input',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1'
                    })
                } else if (v.htmlType === 'select') {
                    let optionData = []
                    if (v.dataType != undefined) {
                        if (v.dataType === '0') {
                            optionData = getDictDatas(v.dictType)
                        } else if (v.dataType === '1') {
                            optionData = JSON.parse(v.jsonData)
                        }
                    }
                    formItem.push({
                        ltype: 'select',
                        placeholder: '请选择' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        multiple: false,
                        width: 'w-1',
                        options: optionData
                    })
                } else if (v.htmlType === 'datetime') {
                    formItem.push({
                        ltype: 'dateTimePicker',
                        type: 'datetime',
                        placeholder: '请选择' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        valueFormat: 'yyyy-MM-dd HH:ss:mm',
                        width: 'w-1'
                    })
                } else if (v.htmlType === 'textarea') {
                    formItem.push({
                        ltype: 'input',
                        type: 'textarea',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1'
                    })
                } else if (v.htmlType === 'radio') {
                    let optionData = []
                    if (v.dataType != undefined) {
                        if (v.dataType === '0') {
                            optionData = getDictDatas(v.dictType)
                        } else if (v.dataType === '1') {
                            optionData = JSON.parse(v.jsonData)
                        }
                    }
                    formItem.push({
                        ltype: 'radio',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1',
                        options: optionData
                    })
                } else if (v.htmlType === 'checkbox') {
                    let optionData = []
                    if (v.dataType != undefined) {
                        if (v.dataType === '0') {
                            optionData = getDictDatas(v.dictType)
                        } else if (v.dataType === '1') {
                            optionData = JSON.parse(v.jsonData)
                        }
                    }
                    formItem.push({
                        ltype: 'checkbox',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1',
                        options: optionData
                    })
                }
                if (this.addFormConfig.formSubmit[v.javaField]) {
                    this.$set(
                        this.addFormConfig.formSubmit,
                        this.addFormConfig.formSubmit[v.javaField],
                        ''
                    )
                }
            }
            this.addFormConfig.formItems.push(formItem)
        },
        /**
         * 构建修改弹框配置
         * @param {Array} data
         */
        bulidUpdateFormConfig(data) {
            //过滤新增表单数据
            let editData = data.filter(v => {
                return v.edit
            })
            this.updateFormConfig.formItems = []
            let formItem = []
            for (var i = 0; i < editData.length; i++) {
                let v = editData[i]
                if (formItem.length > 2) {
                    this.updateFormConfig.formItems.push(formItem)
                    formItem = []
                }
                if (v.htmlType === 'input') {
                    formItem.push({
                        ltype: 'input',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1'
                    })
                } else if (v.htmlType === 'select') {
                    let optionData = []
                    if (v.dataType != undefined) {
                        if (v.dataType === '0') {
                            optionData = getDictDatas(v.dictType)
                        } else if (v.dataType === '1') {
                            optionData = JSON.parse(v.jsonData)
                        }
                    }
                    formItem.push({
                        ltype: 'select',
                        placeholder: '请选择' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        multiple: false,
                        width: 'w-1',
                        options: optionData
                    })
                } else if (v.htmlType === 'datetime') {
                    formItem.push({
                        ltype: 'dateTimePicker',
                        type: 'datetime',
                        placeholder: '请选择' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        valueFormat: 'yyyy-MM-dd HH:ss:mm',
                        width: 'w-1'
                    })
                } else if (v.htmlType === 'textarea') {
                    formItem.push({
                        ltype: 'input',
                        type: 'textarea',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1'
                    })
                } else if (v.htmlType === 'radio') {
                    let optionData = []
                    if (v.dataType != undefined) {
                        if (v.dataType === '0') {
                            optionData = getDictDatas(v.dictType)
                        } else if (v.dataType === '1') {
                            optionData = JSON.parse(v.jsonData)
                        }
                    }
                    formItem.push({
                        ltype: 'radio',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1',
                        options: optionData
                    })
                } else if (v.htmlType === 'checkbox') {
                    let optionData = []
                    if (v.dataType != undefined) {
                        if (v.dataType === '0') {
                            optionData = getDictDatas(v.dictType)
                        } else if (v.dataType === '1') {
                            optionData = JSON.parse(v.jsonData)
                        }
                    }
                    formItem.push({
                        ltype: 'checkbox',
                        placeholder: '请输入' + v.columnComment,
                        label:
                            v.columnComment.length > 4
                                ? v.columnComment.substr(0, 4)
                                : v.columnComment,
                        prop: v.javaField,
                        width: 'w-1',
                        options: optionData
                    })
                }
                if (this.updateFormConfig.formSubmit[v.javaField]) {
                    this.$set(
                        this.updateFormConfig.formSubmit,
                        this.updateFormConfig.formSubmit[v.javaField],
                        ''
                    )
                }
            }
            this.updateFormConfig.formItems.push(formItem)
        },
        //构建验证规则
        bulidFormRule(data) {
            this.addFormConfig.formRule = []
            this.updateFormConfig.formRule = []
            for (var i = 0; i < data.length; i++) {
                let formItem = []
                let v = data[i]
                formItem.push({
                    required: v.required,
                    message: '请输入' + v.columnComment,
                    trigger: 'blur'
                })
                this.addFormConfig.formRule[v.javaField] = formItem
                this.updateFormConfig.formRule[v.javaField] = formItem
            }
        },
        /**
         * 树点击
         * @param {Object} params
         */
        handelTreeClick(params) {
            debugger
            // 初始化查询条件
            this.initQueryParmas()
            this.baseTreeConfig.currentNodeKey = params.item.id
            this.curTableInfo = params.item.data
            if (Object.keys(this.curTableInfo).length > 0) {
                // 组装查询条件
                this.queryTableParams.entity = {
                    tableId: this.curTableInfo.tableId,
                    tableName: this.curTableInfo.tableName
                }
                //查询模型数据
                this.queryBusModelColsData(
                    this.curTableInfo.tableId,
                    this.curTableInfo.tableName
                )
                // 查询数据
                this.queryTableData(this.queryTableParams)
            }
        },

        /**
         * 中间表格相关
         */

        /**
         * 查询表格数据
         */
        async queryTableData(params) {
            this.baseTableConfig.tableConfig.loading = true
            try {
                let res = await busModelDataList(params)
                if (res.data) {
                    this.baseTableConfig.tableData = res.data.list
                    this.paginationConfig.total = res.data.totalCount
                } else {
                    this.baseTableConfig.tableData = []
                    this.paginationConfig.total = 0
                }
                this.baseTableConfig.tableConfig.loading = false
            } catch (error) {
                this.baseTableConfig.tableConfig.loading = false
            }
        },
        /**
         * 表格数据被选中
         */
        tableDataSelected(rows) {
            this.baseTableConfig.tableCheckedDatas = rows
        },
        /**
         * 初始化查询参数
         */
        initQueryParmas() {
            this.queryTableParams = {
                pageNo: 0,
                pageSize: 10,
                entity: {
                    tableId: this.curTableInfo.tableId,
                    tableName: this.curTableInfo.tableName
                }
            }
            this.paginationConfig.size = 10
            this.paginationConfig.currentPage = 1
            this.baseTableConfig.tableData = []
        },
        /**
         * 页码变化
         */
        pageNumberChange(e) {
            this.queryTableParams.pageNo = e
            this.paginationConfig.currentPage = e
            this.queryTableData(this.queryTableParams)
        },
        /**
         * 页大小变化
         */
        pageSizeChange(e) {
            // 页大小变化时，将当前页码设置为0
            this.queryTableParams.pageNo = 0
            // 将当前表格数据设置为空
            this.baseTableConfig.tableData = []
            this.queryTableParams.pageSize = e
            this.queryTableData(this.queryTableParams)
        },

        /**
         * 搜索栏相关
         */
        /**
         * 搜索栏按钮点击
         * @param {Object} params
         */
        searchBarButtonClick(params) {
            // 清空查询参数
            this.initQueryParmas()
            try {
                this[params.prop]()
            } catch (error) {
                throw new Error(error)
            }
        },
        /**
         * 重置搜索表单
         */
        resetSearchForm() {
            // 查询参数初始化
            this.initQueryParmas()
            // 重置搜索表单
            this.$refs.searchForm.resetForm()
            // 查询数据
            this.refreshTableData()
        },

        /**
         * 搜索数据
         */
        searchDatas() {
            this.$refs.searchForm.submitForm(() => {
                // 清空查询参数
                this.initQueryParmas()
                // 组装查询条件
                this.queryTableParams.entity = {
                    tableId: this.curTableInfo.tableId,
                    tableName: this.curTableInfo.tableName,
                    params: this.searchFormConfig.formSubmit
                }
                // 查询数据
                this.queryTableData(this.queryTableParams)
            })
        },

        /**
         * 操作栏相关
         */
        /**
         * 操作项点击
         * @param {*} params
         */
        handelOptionClick(params) {
            this[params] ? this[params]() : null
        },
        /**
         * 切换搜索栏的显示状态
         */
        switchSearchStatus() {
            this.searchFormConfig.searchContenerShow = !this.searchFormConfig
                .searchContenerShow
        },
        /**
         * 刷新表格数据
         */
        refreshTableData() {
            // 将当前表格数据设置为空
            this.baseTableConfig.tableData = []
            this.queryTableData(this.queryTableParams)
        },
        /**
         * 设置表格显示隐藏列(打开弹框)
         */
        switchTableColumn() {
            let dialogParams = {
                title: '显示/隐藏',
                width: 'auto',
                show: true,
                key: 'tableColumn'
            }
            // 设置参与表格列控制的属性（最后的数组为不参与隐藏显示设置的列）
            this.tableColumnTransferConfig.data = assemblyDataByTableColumn(
                this.baseTableConfig.tableHeader,
                'label',
                ['选择', '操作']
            )
            this.handelOpenDialog(dialogParams)
        },
        /**
         * 设置表格显示隐藏列(弹框确认)
         */
        switchTableColumnButtonClick() {
            let newData = this.$refs.baseTransfer.backCheckedData()
            if (newData && newData.length > 0) {
                this.baseTableConfig.tableHeader.forEach(ele => {
                    ele.visible = !newData.includes(ele.label)
                })
            } else {
                this.baseTableConfig.tableHeader.forEach(ele => {
                    ele.visible = true
                })
            }
            this.handelCloseDialog()
        },
        /**
         * 设置(新增、修改)表单的表单项
         */
        async setFormsItems() {},
        /**
         * 新增表格数据(打开弹框)
         */
        addTableData() {
            // 打开新增弹框
            let dialogParams = {
                title: '新增',
                width: '60%',
                show: true,
                key: 'addTableData'
            }
            this.handelOpenDialog(dialogParams)
            this.$nextTick(() => {
                this.initAddForm()
            })
        },
        /**
         * 新增数据确认提交(弹框确认)
         */
        addFormButtonClick() {
            this.$refs['addForm'].submitForm(async res => {
                if (res) {
                    let vo = {
                        tableId: this.curTableInfo.tableId,
                        tableName: this.curTableInfo.tableName,
                        params: res
                    }
                    let assRes = await busModelDataSave(vo)
                    if (assRes && assRes.code === 0) {
                        this.$message.closeAll()
                        this.$message.success({ message: '新增成功！' })
                    } else {
                        this.$message.closeAll()
                        this.$message.error({ message: '新增失败！' })
                    }
                    this.handelCloseDialog()
                    // 查询数据
                    this.refreshTableData()
                    this.initAddForm()
                } else {
                    this.initAddForm()
                }
            })
        },
        /**
         * 初始化新增表单
         */
        initAddForm() {
            this.addFormConfig.formSubmit = {}
            this.$refs.addForm.resetForm()
        },
        /**
         * 修改表格数据(打开弹框)
         */
        async updateTableData(row) {
            this.updateFormConfig.formSubmit = this.$_.cloneDeep(row)
            // 打开修改弹框
            let dialogParams = {
                title: '修改',
                width: '40%',
                show: true,
                key: 'updateTableData'
            }
            this.handelOpenDialog(dialogParams)
        },
        /**
         * 修改数据提交(弹框确认)
         */
        updateFormButtonClick() {
            this.$refs['updateForm'].submitForm(async res => {
                if (res) {
                    let vo = {
                        tableId: this.curTableInfo.tableId,
                        tableName: this.curTableInfo.tableName,
                        params: res
                    }
                    let assRes = await busModelDataUpdate(vo)
                    if (assRes && assRes.code === 0) {
                        this.$message.closeAll()
                        this.$message.success({ message: '修改成功！' })
                    } else {
                        this.$message.closeAll()
                        this.$message.error({ message: '修改失败！' })
                    }
                    this.handelCloseDialog()
                    // 查询数据
                    this.refreshTableData()
                    this.initUpdateForm()
                } else {
                    this.initUpdateForm()
                }
            })
        },
        /**
         * 初始化修改表单
         */
        initUpdateForm() {
            this.updateFormConfig.formSubmit = {}
        },
        /**
         * 删除表格数据
         */
        deleteTableData(rows) {
            let vo = {
                tableId: this.curTableInfo.tableId,
                tableName: this.curTableInfo.tableName,
                params: rows
            }
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(async () => {
                    let res = await busModelDataDelete(vo)
                    if (res && res.code == 0) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        })
                    } else {
                        this.$message({
                            type: 'error',
                            message: '删除失败!'
                        })
                    }
                    // 查询数据
                    this.refreshTableData()
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        },

        //显示明细框
        showSubTableData(row) {
            this.$router.push({
                name: 'SubDataInfo',
                params: {
                    tableInfo: this.curTableInfo,
                    dataId: row[this.curRowDataKey]
                }
            })
        },
        /**
         * 弹框相关
         */
        /**
         * 打开弹框
         * @param {*} params
         */
        handelOpenDialog(params) {
            this.dialogConfig = params
        },
        /**
         * 初始化弹框
         */
        handelInitDialog() {
            this.dialogConfig = {
                title: '',
                show: false,
                width: '',
                key: ''
            }
        },
        /**
         * 关闭弹框
         */
        handelCloseDialog() {
            this.handelInitDialog()
        },
        /**
         * 弹框确定
         */
        handelCofimeDialog() {
            // 表格列筛选的弹框
            if (this.dialogConfig.key === 'tableColumn') {
                this.switchTableColumnButtonClick()
            } else if (this.dialogConfig.key === 'addTableData') {
                this.addFormButtonClick()
            } else if (this.dialogConfig.key === 'updateTableData') {
                this.updateFormButtonClick()
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.more-dropdown {
    margin-left: 10px;
}
.dialog-content {
    @include box_flex(
        $width: 100%,
        $height: auto,
        $direction: column,
        $justify: flex-start,
        $align: center
    );
}
</style>
